package com.finer.service.impl;

import com.finer.entity.finance.FinerMoneyGiveDetail;
import com.finer.dao.FinerMoneyGiveDetailDao;
import com.finer.service.FinerMoneyGiveDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 财务付款详情表(FinerMoneyGiveDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:38
 */
@Service("finerMoneyGiveDetailService")
public class FinerMoneyGiveDetailServiceImpl implements FinerMoneyGiveDetailService {
    @Resource
    private FinerMoneyGiveDetailDao finerMoneyGiveDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerMoneyGiveDetail queryById(Integer id) {
        return this.finerMoneyGiveDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerMoneyGiveDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerMoneyGiveDetail> queryByPage(FinerMoneyGiveDetail finerMoneyGiveDetail, PageRequest pageRequest) {
        long total = this.finerMoneyGiveDetailDao.count(finerMoneyGiveDetail);
        return new PageImpl<>(this.finerMoneyGiveDetailDao.queryAllByLimit(finerMoneyGiveDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerMoneyGiveDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerMoneyGiveDetail insert(FinerMoneyGiveDetail finerMoneyGiveDetail) {
        this.finerMoneyGiveDetailDao.insert(finerMoneyGiveDetail);
        return finerMoneyGiveDetail;
    }

    /**
     * 修改数据
     *
     * @param finerMoneyGiveDetail 实例对象
     * @return 实例对象
     */
    @Override
    public FinerMoneyGiveDetail update(FinerMoneyGiveDetail finerMoneyGiveDetail) {
        this.finerMoneyGiveDetailDao.update(finerMoneyGiveDetail);
        return this.queryById(finerMoneyGiveDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerMoneyGiveDetailDao.deleteById(id) > 0;
    }
}
